package com.manner.groupon.controller.admin;

import com.manner.groupon.common.BaseResponse;
import com.manner.groupon.common.PageResult;
import com.manner.groupon.common.ResultUtils;
import com.manner.groupon.model.dto.search.AdminSearch;
import com.manner.groupon.model.entity.StoreLinkMan;
import com.manner.groupon.model.vo.AdminAssayVO;
import com.manner.groupon.model.vo.AdminLinkManVO;
import com.manner.groupon.model.vo.LoginResultVo;
import com.manner.groupon.service.store.StoreLinkManService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 唐旭成
 * @version 2022.1.2
 * @date 2024/10/9 23:50
 * 管理商家及用户操作
 */
@RestController
@RequestMapping("/admin")

public class AdminController {

    @Resource
    private StoreLinkManService storeLinkManService;

    @GetMapping("/login")
    public BaseResponse<LoginResultVo<StoreLinkMan>> login(String phone, String pwd) {
        return storeLinkManService.login(phone, pwd);
    }

    @GetMapping("/{phone}")
    public BaseResponse<StoreLinkMan> queryByPhone(@PathVariable String phone) {
        StoreLinkMan data = storeLinkManService.query().eq("phone", phone).one();
        return ResultUtils.success(data);
    }

    @GetMapping("/assay")
    public BaseResponse<AdminAssayVO> query() {
        return storeLinkManService.query_assay();
    }

    @GetMapping("/list")
    public BaseResponse<PageResult<AdminLinkManVO>> query(AdminSearch adminSearch) {
        return storeLinkManService.query(adminSearch);
    }

    @PutMapping("/password")
    public BaseResponse<String> editPassword(Long id, String password) {
        storeLinkManService.update().set("password", password).eq("id", id).update();
        return ResultUtils.success("修改成功");
    }
}
